package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.framework.utils.StringUtils;
import com.moyq5.mvc.maker.test.bean.enums.AdminType;
import com.moyq5.mvc.maker.test.bean.enums.SysSex;

/**
 * 管理员
 * 
 * @author Moyq5
 * @date 2018年4月12日
 */
@Entity
@Table(name = "sys_admin")
@DynamicUpdate
public class SysAdmin implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1448673400710350513L;
	/**
	 * 管理员ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "admin_id")
	private Long adminId;
	/**
	 * 管理员类型（多选）
	 * @see {@link AdminType}
	 */
	@Column(name = "type", precision = 8, scale = 0, nullable = false)
	private Integer type;
	/**
	 * 登录名
	 */
    @Column(name = "name", length = 20, nullable = false)
	private String name;
    /**
	 * 是否已经修改过登录名，默认只允许修改一次
	 */
    @Column(name = "named", nullable = false, columnDefinition="int(1) default '0'")
	private Boolean named;
	/**
	 * 密码
	 */
    @Column(name = "pwd", length = 32, nullable = false)
	private String pwd;
	/**
	 * 密码加密参数
	 */
    @Column(name = "salt", length = 20, nullable = false)
	private String salt;
    /**
	 * 昵称
	 */
    @Column(name = "nickname", length = 20, nullable = false)
	private String nickname;
	/**
	 * 姓名
	 */
    @Column(name = "real_name", length = 20, nullable = false)
	private String realName;
    /**
	 * 手机号
	 */
    @Column(name = "mobile", length = 20, nullable = false)
	private String mobile;
    /**
	 * 头像
	 */
    @Column(name = "portrait", length = 200)
	private String portrait;
    /**
	 * 性别
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "sex", columnDefinition="int(1) default '0'")
	private SysSex sex;
    /**
	 *  本次登录时间
	 */
	@Column(name = "cur_time", nullable = false, columnDefinition="datetime")
	private Date curTime;
	/**
	 *  上次登录时间
	 */
	@Column(name = "pre_time", nullable = false, columnDefinition="datetime")
	private Date preTime;
	/**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == pwd) {
			pwd = StringUtils.random(10);
		}
		if (null == salt) {
			salt = StringUtils.random(10);
		}
		if (null == name) {
			name = mobile;
		}
		if (null == nickname) {
			nickname = name;
		}
		if (null == realName) {
			realName = name;
		}
		if (null == addTime) {
			addTime = new Date();
		}
		if (null == preTime) {
			preTime = new Date();
		}
		if (null == curTime) {
			curTime = new Date();
		}
		if (null == named) {
			named = false;
		}
	}
	public Long getAdminId() {
		return adminId;
	}
	public void setAdminId(Long adminId) {
		this.adminId = adminId;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getSalt() {
		return salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public Date getCurTime() {
		return curTime;
	}
	public void setCurTime(Date curTime) {
		this.curTime = curTime;
	}
	public Date getPreTime() {
		return preTime;
	}
	public void setPreTime(Date preTime) {
		this.preTime = preTime;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	public String getPortrait() {
		return portrait;
	}
	public void setPortrait(String portrait) {
		this.portrait = portrait;
	}
	public Boolean getNamed() {
		return named;
	}
	public void setNamed(Boolean named) {
		this.named = named;
	}
	public SysSex getSex() {
		return sex;
	}
	public void setSex(SysSex sex) {
		this.sex = sex;
	}

}
